﻿using System.Windows.Forms;
using System.Data;
using DevExpress.XtraEditors;

namespace Mota.XMLControls
{
    /// <summary>
    /// Represent DateTime visual control based on DX DateEdit control
    /// </summary>
    public class DXGuiDateTime:GuiDateTime
    {
        /// <summary>
        /// Create DateEdit control and set EditMask propertie to "G"
        /// </summary>
        public DXGuiDateTime()
        {
            visualControl = new DateEdit();
            // set to G to show time value, because by default show only date 
            (visualControl as DateEdit).Properties.Mask.EditMask = "G";
            // The DateTime mask mode with the caret automatic movement feature. 
            (visualControl as DateEdit).Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.DateTimeAdvancingCaret;
            (visualControl as DateEdit).EditValueChanged += DXGuiDateTime_EditValueChanged;
            
        }

        void DXGuiDateTime_EditValueChanged(object sender, System.EventArgs e)
        {
            this.ChangeEventCall(null);
        }
        /// <summary>
        /// getter returns Text value of DateEdit control
        /// setter does nothing
        /// </summary>
        public override string Text
        {
            get
            {
                return (visualControl as DateEdit).Text;
            }
            set
            {
                
            }
        }

        /// <summary>
        /// Set editor value by adding DataBinding to DX DAteEdit control on EditValue propertie
        /// </summary>
        /// <param name="valueBinding">main binding with current object values</param>
        public override void SetValue(object valueBinding)
        {
            (visualControl as DateEdit).DataBindings.Add("EditValue", valueBinding as BindingSource, XmlAttributes["XMLAttribute"], true);
        }

        /// <summary>
        /// dummy object for DateTime control
        /// </summary>
        public override object Binding
        {
            get
            {
                return null;
            }
            set
            {
                //throw new System.NotImplementedException();
            }
        }

        public override object GetValue()
        {
            return (visualControl as DateEdit).EditValue;
        }
    }

}
